package com.ray.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.bean.DatatablesViewPageBean;
import com.ray.exception.ServiceException;
import com.ray.service.EnergyService;
import com.ray.service.FinanceService;
import com.ray.service.StructureTreeService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;

@Controller
@RequestMapping("/finance")
public class FinanceController {
	@Autowired
	FinanceService financeService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/{methodName}")
	@ResponseBody
	private Map<String, Object> addAirFlowControl(HttpServletRequest request,HttpServletResponse response,
			@PathVariable("methodName") String methodName) throws NoSuchMethodException, SecurityException, IllegalAccessException {
		Map<String, Object> requestParamMap = RequestUtil.getRequestAllParam(request);
		requestParamMap.put("request", request);
		requestParamMap.put("response", response);
		Method targetMethod = financeService.getClass().getMethod(urlMethodMappingMap.get(methodName), Map.class);
		Object object=null;
		try {
			 object=targetMethod.invoke(financeService, requestParamMap);
		}catch(InvocationTargetException e) {
			if(e.getCause().getClass()== IllegalArgumentException.class || e.getCause().getClass() ==ServiceException.class) {
				e.printStackTrace();
				Assert.notNull(null,e.getTargetException().getMessage());
			}else {
				e.printStackTrace();
				return ResponseUtil.ResponseError("网络不好，请稍等。。。。");
			}
		}
		return ResponseUtil.ResponseResult(object);
	}

	/**
	 *  方法名和请求路径映射
	 */
	private static  Map<String, String> urlMethodMappingMap;
	static{
		urlMethodMappingMap=new HashMap<String,String>();
		urlMethodMappingMap.put("addBank", "addBank");//添加银行卡
		urlMethodMappingMap.put("updateBank", "updateBank");//添加银行卡
		urlMethodMappingMap.put("getAllBank", "getAllBank");//获取所有银行卡
		urlMethodMappingMap.put("approvalReceiptPaymentRecord", "approvalReceiptPaymentRecord");//审核收付款记录
		urlMethodMappingMap.put("getReceivePaymentRecord", "getReceivePaymentRecord");//获取收付款记录
		urlMethodMappingMap.put("getReceiptPaymentRecordByInOutId", "getReceiptPaymentRecordByInOutId");//获取出入库收付款信息
		urlMethodMappingMap.put("getReceiptPaymentRecordByMainId", "getReceiptPaymentRecordByMainId");//获取某次收付款明细
		urlMethodMappingMap.put("verificationReceiptPaymentRecord", "verificationReceiptPaymentRecord");//核销收付款记录
		urlMethodMappingMap.put("exportReceivePaymentRecord", "exportReceivePaymentRecord");//导出收付款记录
		urlMethodMappingMap.put("supplementInvoicData", "supplementInvoicData");//补充开票信息
		//预售付款接口
		urlMethodMappingMap.put("advancePayAdd", "advancePayAdd");//添加预收付款信息
		urlMethodMappingMap.put("approvalAdvancePayBatch", "approvalAdvancePayBatch");//批量审核预付款记录
		urlMethodMappingMap.put("getAdvancePayRecord", "getAdvancePayRecord");//批量审核预付款记录
		
		//对账单接口
		urlMethodMappingMap.put("getAccountStatement", "getAccountStatement");//对账单接口
		
	}
	
}
